package com.lianniu.mgr.productAssess.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.lianniu.mgr.base.BaseResult;
import com.lianniu.mgr.constants.ErrorCode;
import com.lianniu.mgr.pagination.PaginationInfo;
import com.lianniu.mgr.productAssess.dao.IProductAssessDao;
import com.lianniu.mgr.productAssess.model.ProductAssessVo;
import com.lianniu.mgr.productAssess.service.IProductAssessService;
import com.lianniu.mgr.util.StringUtil;
@Service
public class ProductAssessServiceImpl implements IProductAssessService{

	private final static Logger logger = Logger.getLogger(ProductAssessServiceImpl.class);
	
	@Resource
	IProductAssessDao productAssessDao;
	
	@Override
	public BaseResult selectByProductAssessForPage(ProductAssessVo curProductAssessVo, PaginationInfo paginationInfo) {
		logger.info("selectByProductAssessForPage begin.");
	    if (!StringUtil.isEmpty(curProductAssessVo.getSupplyProductId())) {
	    	curProductAssessVo.setSupplyProductId(curProductAssessVo.getSupplyProductId().replace(" ", ""));
	    }
	    logger.info("selectByProductAssessForPage SupplyProductId:" +curProductAssessVo.getSupplyProductId());
	    if (!StringUtil.isEmpty(curProductAssessVo.getId())) {
	    	curProductAssessVo.setId(curProductAssessVo.getId().replace(" ", ""));
	    }
	    logger.info("selectByProductAssessForPage Id:" +curProductAssessVo.getId());
	    if (!StringUtil.isEmpty(curProductAssessVo.getOrderId())) {
	    	curProductAssessVo.setOrderId(curProductAssessVo.getOrderId().replace(" ", ""));
	    }
	    logger.info("selectByProductAssessForPage OrderId:" +curProductAssessVo.getOrderId());
	    logger.info("selectByProductAssessForPage paginationInfo:" +JSON.toJSONString(paginationInfo));
	    
	    curProductAssessVo.setPaginationInfo(paginationInfo);
	    List<ProductAssessVo> list=productAssessDao.selectByProductAssessForPage(curProductAssessVo);
	    Map<String,Object> retmap=new HashMap<String,Object>();
	    retmap.put("total", paginationInfo.getTotalRecord());
	    retmap.put("curPage", paginationInfo.getCurPage());
	    retmap.put("rows", list);
	    logger.info("selectByProductAssessForPage:  end");    
	    
	    return BaseResult.success(retmap); 
	}

	@Override
	public BaseResult selectById(ProductAssessVo curProductAssessVo) {
		logger.info("selectById begin");
	    logger.info("selectById Id:" +curProductAssessVo.getId());
	  
	    return BaseResult.success(productAssessDao.selectById(curProductAssessVo.getId()));
	}

	@Override
	public BaseResult deleteById(String id) {
		logger.info("deleteById begin");
		 logger.info("deleteById Id:" +id);
		  
		 return BaseResult.success(productAssessDao.deleteById(id));
	}

	@Override
	public BaseResult deleteProductAssess(String... id) {
		logger.info("deleteProductAssess begin");
	    logger.info("deleteProductAssess Ids:" +id.toString());
	    logger.info("deleteProductAssess: input data check begin");
	   
	    BaseResult baseResult;
	    if (StringUtil.isEmpty(id.toString())) {
	      baseResult =  BaseResult.fail(ErrorCode.ParaCheckErrorRetCode, ErrorCode.ParaCheckErrorRetInfo);
	      return baseResult;
	    }
	    logger.info("deleteProductAssess: input data check end");
	    
	    return BaseResult.success(productAssessDao.deleteProductAssess(id));
	}

}
